package view.carte;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import server.models.PosteDeTir;
import view.utils.ImageUtil;

import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;

public class CarteView extends JPanel {
	private static final String CARTE_JPG = "view/ressources/carte.jpg";
	private static final long serialVersionUID = 1L;
	/**
	 * Image de la carte.
	 */
	private Image carte;
	public CarteView(ArrayList<PosteDeTir> postesModele){

		this.carte = ImageUtil.getImageIcon(this, CarteView.CARTE_JPG).getImage();        
		setDoubleBuffered(true);
		
		//this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		this.setLayout(null);
		
		this.addPosteDeTir(postesModele.get(0),100,100);
		this.addPosteDeTir(postesModele.get(1),100,200);
		this.addPosteDeTir(postesModele.get(2),130,280);
		this.addPosteDeTir(postesModele.get(3),200,350);
		this.addPosteDeTir(postesModele.get(4),300,280);
		this.addPosteDeTir(postesModele.get(5),350,200);
		this.addPosteDeTir(postesModele.get(6),380,100);
		this.addPosteDeTir(postesModele.get(7),220,100);
		this.repaint();
	}

	private void addPosteDeTir(PosteDeTir posteDeTir, int x, int y) {
		PosteDeTirView poste = new PosteDeTirView(posteDeTir);
		poste.setBounds(x, y, 1000, 1000);
		poste.setLayout(null);
		poste.setSize(100,100);
		this.add(poste);
	}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawImage(carte, 0, 0, null);
	}
}
